{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1, 2, 3)\n",
      "(1, 3, 2)\n",
      "(2, 1, 3)\n",
      "(2, 3, 1)\n",
      "(3, 1, 2)\n",
      "(3, 2, 1)\n"
     ]
    }
   ],
   "source": [
    "\n",
    "'''\n",
    "对Python的用法不做深入记录\n",
    "'''\n",
    "\n",
    "# itertools提供了很多生成循环器的工具\n",
    "import itertools\n",
    "\n",
    "items = [1,2,3]\n",
    "\n",
    "# permutations 考虑顺序组合元素\n",
    "for item in itertools.permutations(items):\n",
    "    print(item)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1, 2)\n",
      "(1, 3)\n",
      "(2, 3)\n"
     ]
    }
   ],
   "source": [
    "# combinations() 函数, 不考虑顺序 不放回数据\n",
    "for item in itertools.combinations(items, 2):\n",
    "    print(item)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1, 1)\n",
      "(1, 2)\n",
      "(1, 3)\n",
      "(2, 2)\n",
      "(2, 3)\n",
      "(3, 3)\n"
     ]
    }
   ],
   "source": [
    "# combinations_with_replacement, 不考虑顺序，有放回\n",
    "for item in itertools.combinations_with_replacement(items, 2):\n",
    "    print(item)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('a', 'c')\n",
      "('a', 'd')\n",
      "('b', 'c')\n",
      "('b', 'd')\n"
     ]
    }
   ],
   "source": [
    "# product() 函数 笛卡尔积 对应元素全部组合\n",
    "ab = ['a','b']\n",
    "cd = ['c','d']\n",
    "\n",
    "for item in itertools.product(ab,cd):\n",
    "    print(item)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 由于全局解释锁，GIL， Python的线程被限制在同一时刻只容许一个线程在运行，所以Python的多线程适用于处理I/O 密集型任务和并发执行的阻塞操作\n",
    "# 多进程处理并行的计算密度型任务\n",
    "\n",
    "# concurrent.futures库\n",
    "\n",
    "# 多线程 ThreadPoolExecutor"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 上下文管理器\n",
    "# with A_class as a:\n",
    "#     do things\n",
    "# 进入上下文管理 会触发__enter__(), 离开上下文, 会触发 __exit__()\n",
    "# 在这两者中执行相反的操作\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Python一大特点是简洁，但是在金融量化领域，不建议使用过短的变量名，类名，函数名；"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
